//
//  GetWeiboAccount.m
//  weibo
//
//  Created by DYC on 16/7/4.
//  Copyright © 2016年 DP. All rights reserved.
//

#import "GetWeiboAccount.h"
#import "WBAccount.h"

#define AccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.archive"]
@implementation GetWeiboAccount

+ (void)saveAccount:(WBAccount *)account {
    [NSKeyedArchiver archiveRootObject:account toFile:AccountPath];
}

+ (WBAccount *)getAccount {
    WBAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:AccountPath];
    if (account == nil) {
        return nil;
    }
    
    NSDate *date = [NSDate date];
    NSTimeInterval time = [account.wbExpirationDate timeIntervalSinceDate:date];
    if (time <= 0) {
        return nil;
    }
    
    return account;
    
}

+ (BOOL)removeAccount {
    
    return [[NSFileManager defaultManager] removeItemAtPath:AccountPath error:nil];
}
@end
